package com.fuxi.cloud.common.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fuxi.cloud.common.constant.CommonConstant;

import java.io.Serializable;

/**
 * Result
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */

public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private boolean success = true;
    private String message = "";
    private Integer code = 0;
    private T result;
    private long timestamp = System.currentTimeMillis();
    @JsonIgnore
    private String onlTable;

    public Result() {
    }

    public Result<T> success(String message) {
        this.message = message;
        this.code = CommonConstant.SC_OK_200;
        this.success = true;
        return this;
    }

    /** @deprecated */
    @Deprecated
    public static Result<Object> ok() {
        Result var0 = new Result();
        var0.setSuccess(true);
        var0.setCode(CommonConstant.SC_OK_200);
        var0.setMessage("成功");
        return var0;
    }

    /** @deprecated */
    @Deprecated
    public static Result<Object> ok(String msg) {
        Result var1 = new Result();
        var1.setSuccess(true);
        var1.setCode(CommonConstant.SC_OK_200);
        var1.setMessage(msg);
        return var1;
    }

    /** @deprecated */
    @Deprecated
    public static Result<Object> ok(Object data) {
        Result var1 = new Result();
        var1.setSuccess(true);
        var1.setCode(CommonConstant.SC_OK_200);
        var1.setResult(data);
        return var1;
    }

    public static <T> Result<T> OK() {
        Result var0 = new Result();
        var0.setSuccess(true);
        var0.setCode(CommonConstant.SC_OK_200);
        return var0;
    }

    public static <T> Result<T> OK(T data) {
        Result var1 = new Result();
        var1.setSuccess(true);
        var1.setCode(CommonConstant.SC_OK_200);
        var1.setResult(data);
        return var1;
    }

    public static <T> Result<T> OK(String msg, T data) {
        Result var2 = new Result();
        var2.setSuccess(true);
        var2.setCode(CommonConstant.SC_OK_200);
        var2.setMessage(msg);
        var2.setResult(data);
        return var2;
    }

    public static <T> Result<T> FAIL(String msg, T data) {
        Result var2 = new Result();
        var2.setSuccess(false);
        var2.setCode(CommonConstant.SC_OK_200);
        var2.setMessage(msg);
        var2.setResult(data);
        return var2;
    }

    public static Result<Object> error(String msg) {
        return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
    }

    public static Result<Object> error(int code, String msg) {
        Result var2 = new Result();
        var2.setCode(code);
        var2.setMessage(msg);
        var2.setSuccess(false);
        return var2;
    }

    public Result<T> error500(String message) {
        this.message = message;
        this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
        this.success = false;
        return this;
    }

    public static Result<Object> noauth(String msg) {
        return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg);
    }

    public boolean isSuccess() {
        return this.success;
    }

    public String getMessage() {
        return this.message;
    }

    public Integer getCode() {
        return this.code;
    }

    public T getResult() {
        return this.result;
    }

    public long getTimestamp() {
        return this.timestamp;
    }

    public String getOnlTable() {
        return this.onlTable;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    @JsonIgnore
    public void setOnlTable(String onlTable) {
        this.onlTable = onlTable;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Result)) {
            return false;
        } else {
            Result var2 = (Result)o;
            if (!var2.canEqual(this)) {
                return false;
            } else if (this.isSuccess() != var2.isSuccess()) {
                return false;
            } else if (this.getTimestamp() != var2.getTimestamp()) {
                return false;
            } else {
                label64: {
                    Integer var3 = this.getCode();
                    Integer var4 = var2.getCode();
                    if (var3 == null) {
                        if (var4 == null) {
                            break label64;
                        }
                    } else if (var3.equals(var4)) {
                        break label64;
                    }

                    return false;
                }

                label57: {
                    String var5 = this.getMessage();
                    String var6 = var2.getMessage();
                    if (var5 == null) {
                        if (var6 == null) {
                            break label57;
                        }
                    } else if (var5.equals(var6)) {
                        break label57;
                    }

                    return false;
                }

                Object var7 = this.getResult();
                Object var8 = var2.getResult();
                if (var7 == null) {
                    if (var8 != null) {
                        return false;
                    }
                } else if (!var7.equals(var8)) {
                    return false;
                }

                String var9 = this.getOnlTable();
                String var10 = var2.getOnlTable();
                if (var9 == null) {
                    if (var10 != null) {
                        return false;
                    }
                } else if (!var9.equals(var10)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof Result;
    }

    @Override
    public int hashCode() {
        boolean var1 = true;
        byte var2 = 1;
        int var9 = var2 * 59 + (this.isSuccess() ? 79 : 97);
        long var3 = this.getTimestamp();
        var9 = var9 * 59 + (int)(var3 >>> 32 ^ var3);
        Integer var5 = this.getCode();
        var9 = var9 * 59 + (var5 == null ? 43 : var5.hashCode());
        String var6 = this.getMessage();
        var9 = var9 * 59 + (var6 == null ? 43 : var6.hashCode());
        Object var7 = this.getResult();
        var9 = var9 * 59 + (var7 == null ? 43 : var7.hashCode());
        String var8 = this.getOnlTable();
        var9 = var9 * 59 + (var8 == null ? 43 : var8.hashCode());
        return var9;
    }

    @Override
    public String toString() {
        return "Result(success=" + this.isSuccess() + ", message=" + this.getMessage() + ", code=" + this.getCode() + ", result=" + this.getResult() + ", timestamp=" + this.getTimestamp() + ", onlTable=" + this.getOnlTable() + ")";
    }
}
